// ContentEditable trials
//No effect :(
//elmt.observe('focus', function(evt){elmt.setAttribute('contenteditable','true')});
//elmt.observe('blur', function(evt){elmt.removeAttribute('contenteditable')});


function NotebookList_observe(){
    $$('#listNotebooks li').each(function (elmt){
        if(Prototype.Browser.Opera)
            elmt.observe('mouseup', Notebook_onDrop);
        else
            elmt.observe('mouseover', Notebook_onDrop);
    });
}

function Notebook_onDrop(evt){
    return; //TODO for 1.30
    var source = Drag_getSource();
    if(!source) return;

    var target = evt.target.up('li').down('a');
    if(!target)
        return;

    if(!confirm("Copy the selected notes to this notebook?"))
        return;
    
    gxTransfer = window.open(target.href);
    waitForTransfer(source);
}

var gxTransferTimer = null;
function waitForTransfer(source){
    if(source)
        waitForTransfer.dropped = source;
    if(!gxTransfer){
        if(gxTransferTimer) {clearTimeout(gxTransferTimer); gxTransferTimer = null;}
        else gxTransferTimer = setTimeout ( "waitForTransfer()", 2000);
        return;
    }

    if(!(gxTransfer.document.readyState === 'complete')){
            alert("Timeout");
            if(gxTransferTimer) clearTimeout(gxTransferTimer);
            gxTransferTimer = setTimeout ( "waitForTransfer()", 2000);
            return;
    }

   alert("Transferred.");
   var insertLocation = gxTransfer.document.getElementById('Scrapbook');
   insertLocation.insert({top:"Hello"});
}


function traverseVisible(target, cursor, depth)
{
    if (cursor.visible()){
        var text = '';
        var i=0;
        var tagName=cursor.tagName;

        if (tagName)
          target.write("<"+tagName+">");

        var cursorChild= cursor.childElements()[i];
        while (cursorChild){
          if(cursorChild.visible()){
              text = Prototype.Browser.IE? cursorChild.innerText:cursorChild.textContent;
              if(!text.blank())
                  target.write(text);
              traverseVisible(target, cursorChild, depth+1);
          }
          i++;
          cursorChild=cursor.childElements()[i];
        }

        if (tagName)
          target.writeln("</"+tagName+">");
    }
}
